package com.bcmusic.distri.controller;

import com.bcmusic.distri.pojo.DistributeDetail;
import com.bcmusic.distri.service.DistributeDetailService;
import com.github.pagehelper.PageInfo;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:admin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/distributeDetail")
@CrossOrigin
public class DistributeDetailController {

    @Autowired
    private DistributeDetailService distributeDetailService;

    /***
     * DistributeDetail分页条件搜索实现
     * @param distributeDetail
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false) DistributeDetail distributeDetail, @PathVariable  int page, @PathVariable  int size){
        //调用DistributeDetailService实现分页条件查询DistributeDetail
        PageInfo<DistributeDetail> pageInfo = distributeDetailService.findPage(distributeDetail, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * DistributeDetail分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用DistributeDetailService实现分页查询DistributeDetail
        PageInfo<DistributeDetail> pageInfo = distributeDetailService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param distributeDetail
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<DistributeDetail>> findList(@RequestBody(required = false) DistributeDetail distributeDetail){
        //调用DistributeDetailService实现条件查询DistributeDetail
        List<DistributeDetail> list = distributeDetailService.findList(distributeDetail);
        return new Result<List<DistributeDetail>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Integer id){
        //调用DistributeDetailService实现根据主键删除
        distributeDetailService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改DistributeDetail数据
     * @param distributeDetail
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody DistributeDetail distributeDetail, @PathVariable Integer id){
        //设置主键值
        distributeDetail.setDistributeDetailId(id);
        //调用DistributeDetailService实现修改DistributeDetail
        distributeDetailService.update(distributeDetail);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增DistributeDetail数据
     * @param distributeDetail
     * @return
     */
    @PostMapping
    public Result add(@RequestBody DistributeDetail distributeDetail){
        //调用DistributeDetailService实现添加DistributeDetail
        distributeDetailService.add(distributeDetail);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询DistributeDetail数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<DistributeDetail> findById(@PathVariable Integer id){
        //调用DistributeDetailService实现根据主键查询DistributeDetail
        DistributeDetail distributeDetail = distributeDetailService.findById(id);
        return new Result<DistributeDetail>(true,StatusCode.OK,"查询成功",distributeDetail);
    }

    /***
     * 查询DistributeDetail全部数据
     * @return
     */
    @GetMapping
    public Result<List<DistributeDetail>> findAll(){
        //调用DistributeDetailService实现查询所有DistributeDetail
        List<DistributeDetail> list = distributeDetailService.findAll();
        return new Result<List<DistributeDetail>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
